#ifndef PICTUREITEM_H
#define PICTUREITEM_H

#include <QGraphicsRectItem>
#include <QStyleOptionGraphicsItem>
#include <QPainter>
#include <QPixmap>
#include <QStateMachine>
#include <QTimeLine>
#include <QDebug>
#include <QPropertyAnimation>
#include "PictureLoaderThread.h"

enum EState
{
    EState_Down,
    EState_Middle,
    EState_Up,
    EState_Open,
};
class PictureItem : public QObject , public QGraphicsRectItem
{
    Q_OBJECT
    // Change picture position
    Q_PROPERTY(QRectF rect READ rect WRITE setRect)
public:
    explicit PictureItem( PictureData* picData, QGraphicsItem * parent = 0);
    virtual ~PictureItem(){}

    void paint ( QPainter * painter, const QStyleOptionGraphicsItem *, QWidget *  );
    void initAnimations(int nCount);
    QRectF boundingRect () const;

    bool  isAnimating();
signals:
    void emitSeleted();
    void select(const QString& path);

protected:
    virtual void mouseMoveEvent ( QGraphicsSceneMouseEvent * event );
    virtual void mousePressEvent ( QGraphicsSceneMouseEvent * event );
    virtual void mouseReleaseEvent ( QGraphicsSceneMouseEvent * event );
    virtual void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event);

public slots:

    void updateStep1(qreal step);
    void stateChanged1(QTimeLine::State);
    void updateStep2(qreal step);
    void stateChanged2(QTimeLine::State);
    void updateStep3(qreal step);
    void stateChanged3(QTimeLine::State);

    void anim1();
    void anim2();
    void anim3();
    void animFinish1();
    void animFinish2();
    void animFinish3();

    PictureItem* nextPreItem(bool bNext = true);
    EState getState() const { return mState; }

private:
    PictureData*  mPicData;

    QTimeLine *mTimeLine1;
    QTimeLine *mTimeLine2;
    QTimeLine *mTimeLine3;

    QPropertyAnimation* mAnim;

    bool       mIsLeft;
    int        mNum;
    int        mViewMode;

    EState     mState;
    QPointF    mMousePosR;
    QTransform mCurTransForm;
    QTransform mTransForms[3];
};

#endif // PICTUREITEM_H
